package com.demo.books;

import com.demo.common.model.Books;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * 本 com.demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法
 * 详见 JFinal 俱乐部: http://jfinal.com/club
 * 
 * BookValidator.
 */
public class BookValidator extends Validator {
	
	protected void validate(Controller controller) {
		//validateRequiredString("books.bookno", "bookNoMsg", "请输入图书编号!");
		validateRequiredString("books.bookname", "bookNameMsg", "请输入图书名称!");
		validateRequiredString("books.author", "authorMsg", "请输入作者!");
		validateRequiredString("books.publisher", "publisherMsg", "请输入出版社!");
		validateRequiredString("books.introduce", "introduceMsg", "请输入图书简介!");
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(Books.class);
		
		String actionKey = getActionKey();
		if (actionKey.equals("/books/save"))
			controller.render("add.html");
		else if (actionKey.equals("/books/update"))
			controller.render("edit.html");
	}
}
